<template>
	<view class="">
		<view class="text-center top-title">
			发布对象选择
		</view>
		<view class="publish-choice">
			<!-- <view class="title">
				<radio class='blue' :class="radio=='0'?'checked':''" :checked="radio=='0'?true:false" value="0" @tap="changeRadio(0)"></radio>
				<text>全部专属代招发布</text>
			</view> -->
			<view class="title">
				<!-- <radio class='blue' :class="radio=='2'?'checked':''" :checked="radio=='2'?true:false" value="2" @tap="changeRadio(2)"></radio> -->
				<u-checkbox v-model="allGroudId" active-color="#E04110" @change="allGroupLsit">全选</u-checkbox>
				<text>分社群筛选发布</text>
				<view class="publishList">
					<u-checkbox-group active-color="#E04110">
						<u-checkbox class="checkbox flex" v-model="item.checked" v-for="item in toPublishList" :key="item.gid" :name="item.gid">
							<view class="flex">
								<!-- <image v-if="item.headImg" class="headImg" :src="item.headImg"></image> -->
								<view>{{ item.name }}</view>
							</view>
						</u-checkbox>
					</u-checkbox-group>
				</view>
			</view>
			<view class="title">
				<u-checkbox-group active-color="#E04110">
					<u-checkbox class="checkbox more flex" @change="checkMoreList" v-model="item.checked" v-for="item in moreList" :key="item.id" :name="item.id">
						<view>{{ item.name }}</view>
					</u-checkbox>
				</u-checkbox-group>
			</view>
			<!-- <view class="title">
				<radio class='blue' :class="radio=='1'?'checked':''" :checked="radio=='1'?true:false" value="1"  @tap="changeRadio(1)"></radio>
				<text>临时工</text>
				<view class="dayChange" v-for="item in moneylist" :key="item.day_id">
					<view class="daytoOrder" v-if="item.day_id=='1'">
						<text class="day" :class="item.day_num == days && radio=='1'?'dayactive':''" @tap="changeOrder1(item.day_num,item.day_money)">{{item.day_title}}</text>
						<text class="money" v-if="item.day_money>0"><text class="money_span">{{item.day_money}}</text>元</text>
						<text class="tishi1" v-if="item.day_money==0">免费发布</text>
					</view>
					
				</view>
			</view> -->
			
		</view>
		<view class="btn-box">
			<!-- <u-button shape="circle" :custom-style="custom1" @click="payByBalance">余额支付</u-button> -->
			<u-button shape="circle" :custom-style="custom2" @click="toSubmit">确定</u-button>
		</view>
	</view>
</template>

<script>
	import Bus from './bus.js'
	export default {
		data(){
			return {
				allGroudId: false,
				radio : '1',
				groupList: [],
				recruit_id : 0,
				form: {},
				// is_open: null,
				// group_ids: [],
				custom2: {
					'background':'#E04110',
					'color': '#fff',
				},
				toPublishList: [{
					name:'社群1',
					gid: 1,
					checked: false
				},{
					name:'张三',
					gid: 2,
					headImg: '../../static/image/bg2.png',
					checked: false
				}],
				moreList: [{
					name:'面向其他更多一线招工中介公开发布',
					id: 1,
					checked: true
				}],
				moneylist:'',
				money:0,
				days:'3'
			}
		},
		onLoad(e = {}) {
			// if(e.group_ids) {
			// 	this.group_ids = e.group_ids.split(',') || []
			// 	this.is_open = e.is_open || null
			// } 
			this.$u.api.getGroupMembers().then(res =>{
				if (res.status == true) { 
					res.data.map(item => {
						item.checked = false
					})
					this.toPublishList = res.data
					const formData = uni.getStorageSync('formData')
					this.form = formData
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none',
						duration: 2000
					});
				}
			})
		},
		mounted() { 
			// console.log('我执行了吗？？')
			// let that = this
			// const data = Bus.getObj/*  */()
			// Bus.$on('submitData', (data) => {
			// 	console.log(data, this)
			//    that.form = data
			// })
			console.log(Bus)
		},
		methods:{
			allGroupLsit(e) {
				this.toPublishList.map(item => {
					item.checked = e.value
				})
				// this.toPublishList = this.toPublishList
			},
			toSubmit() {
				let group_ids = this.toPublishList.reduce((total, item) => {
					if(item.checked) total.push(item.gid)
					return total
				}, [])
				this.form.is_open = Number(this.moreList[0].checked)
				this.form.group_ids = group_ids.join(',')
				this.loading = true;
					this.$u.api.postSaveOrUpdateActivity(this.form).then(res => {
						if (res.status == true) {
							uni.navigateBack({
								
							})
							// uni.redirectTo({
								// url: '/pages/talent/share'
								// url: '/pages/talent/publish-choice?aid=' + res.data.recruit_id
							// })
						}
						this.loading = false;
					}).catch(error => {
						this.loading = false;
					})
				// } else {
				// 	uni.showToast({
				// 		title: '请先勾选群组！',
				// 		icon: 'none'
				// 	})
				// }
				// uni.navigateBack()
				// console.log(prevPage)
				// prevPage.setData({)
				
			},
			checkboxChange(e){
				console.log(e)
			},
			checkMoreList(e){
				console.log(e)
			},
			// changeOrder1(day,money){
			// 	this.radio = 1;
			// 	this.money = money;
			// 	this.days = day;
			// },
			// changeRadio(radio){
			// 	this.radio = radio;
				// if(this.radio ==2){
					// this.days = 3;
				// }else{
				// 	this.days = '';
				// }
				
			// 	console.log(this.days);
			// },
			// getMoney(){
			// 	let params = {};
			// 	this.$u.api.postCashPledge(params).then(res=>{
			// 		if(res.status == true) {
			// 			this.moneylist = res.data;
			// 		}
			// 	})
			// },
			toPay(){
				let params = {
					types: this.radio, 
					recruit_id: this.recruit_id,
					// money:this.money,
					// days:this.days
				}
				this.$u.api.postOrder(params).then(res => {
					if(res.status == true) {
						var _self = this;
						console.log(_self.radio)
						if(_self.radio == 2){
							if(this.money !=0){
								uni.navigateTo({
									url: '/pages/talent/pay-commission?deposit=' + this.money + '&id=' + res.data.order_id + '&day=' +this.days
								})
							}else{
								uni.navigateTo({
									url: '/pages/talent/share'
								})
							}
							
						}else{
							if(this.money !=0){
								uni.navigateTo({
									url: '/pages/talent/pay-commission?deposit=' + this.money + '&id=' + res.data.order_id + '&day=' +this.days
								})
							}else{
								uni.navigateTo({
									url: '/pages/talent/share'
								})
							}
						}
						
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.text-center{
		text-align: center;
	}
	.top-title{
		margin: 20upx;
		font-size: 54upx;
		font-weight: bold;
	}
	.money_span{
		display: inline-block;
		width:70upx;
	}
	.publish-choice{
		padding: 0 60upx;
		.publishList{
			margin: 30upx;
			padding: 20upx;
			border: 1px solid #000;
		}
		.flex{
			margin: 10upx 0;
			align-items: center;
			.headImg{
				width: 60upx;
				height: 60upx;
				border-radius: 100upx;
				margin: 0 10upx;
			}
			view{
				margin: 0 10upx;
			}
		}
	}
	.more{
		font-size: 50upx;
	}
	.tishi1{
		color:#DD524D;
		margin-left:40upx;
	}
	
	.dayactive{
		border:8upx solid #DD524D;
		background: #DD524D;
		color:#fff;
	}
	
	.btn-box {
		margin-top: 278upx;
	}
	
	.title {
		font-size:50upx;
		font-weight:500;
		color:rgba(51,51,51,1);
		margin-left:40upx;
		margin-top:60upx;
		/* text-align: center; */
	}
	
	.dayChange{
		margin:20upx;
	}
	
	.daytoOrder{
		margin:20upx 0;
	}
	
	.day{
		display: inline-block;
		width:200upx;
		text-align: center;
		border:8upx solid #808080;
		font-size: 30upx;
	}
	
	.money{
		display: inline-block;
		margin-left:40upx;
		font-size:30upx;
	}
</style>
